package com.yunji.base.convert;

import com.yunji.base.cache.BaseCache;
import com.yunji.base.dao.IStaffSiteDao;
import com.yunji.base.domain.StaffSiteDO;
import com.yunji.base.vo.StaffVO;
import com.yunji.common.model.domain.StaffDO;
import com.yunji.common.utils.bean.BeanUtils;

import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2024/12/13 21:17
 * @description : TODO
 **/
public class StaffConvert {

    public static StaffVO domain2VO(StaffDO staff, IStaffSiteDao staffSiteDao) {
        StaffVO staffVO = new StaffVO();
        BeanUtils.clone(staff, staffVO);
        List<StaffSiteDO> staffSites = staffSiteDao.listByStaffId(staff.getId());
        Long[] longs = staffSites.stream().map(StaffSiteDO::getSiteId).toArray(Long[]::new);
        // 加入绑定的站点信息
        staffVO.setSiteName(BaseCache.getSiteName(staff.getManagerId()));
        staffVO.setBindSites(longs);
        staffVO.setBindSitesShow(staffSites);
        return staffVO;
    }

}
